package com.ruoyi.web.controller.edh;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BillType;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.edh.domain.EdhBill;
import com.ruoyi.edh.service.IEdhBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 易订货-账单Controller
 *
 * @author xxx
 * @date 2020-09-07
 */
@RestController
@RequestMapping("/edh/bill")
@Api(description = "易订货-账单")
public class EdhBillController extends BaseController {
    @Autowired
    private IEdhBillService edhBillService;

    /**
     * 查询易订货-账单列表
     */
    @GetMapping("/list")
    @ApiOperation("查询所有账单列表")
    public TableDataInfo list(EdhBill edhBill) {
        startPage();
        List<EdhBill> list = edhBillService.selectEdhBillList(edhBill);
        return getDataTable(list);
    }

    /**
     * 查询本人的账单列表
     */
    @GetMapping("/minelist")
    @ApiOperation("查询本人的账单列表")
    public TableDataInfo mineList(EdhBill edhBill) {
        startPage();
        List<EdhBill> list = edhBillService.mineList(edhBill);
        return getDataTable(list);
    }

    /**
     * 导出易订货-账单列表
     */
    @Log(title = "易订货-账单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出易订货-账单列表")
    public AjaxResult export(EdhBill edhBill) {
        List<EdhBill> list = edhBillService.selectEdhBillList(edhBill);
        ExcelUtil<EdhBill> util = new ExcelUtil<EdhBill>(EdhBill.class);
        return util.exportExcel(list, "bill");
    }

    /**
     * 获取易订货-账单详细信息
     */
    @GetMapping
    @ApiOperation("获取易订货-账单详细信息")
    public AjaxResult getInfo(Long id) {
        return AjaxResult.success(edhBillService.selectEdhBillById(id));
    }


    /**
     * 新增易订货-账单
     */
    @Log(title = "易订货-账单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增易订货-账单")
    public AjaxResult add(@RequestBody EdhBill edhBill) {
        return toAjax(edhBillService.insertEdhBill(edhBill, BillType.BUY, BillType.CUT));
    }

    /**
     * 修改易订货-账单
     */
    @Log(title = "易订货-账单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改易订货-账单")
    public AjaxResult edit(@RequestBody EdhBill edhBill) {
        return toAjax(edhBillService.updateEdhBill(edhBill));
    }

    /**
     * 删除易订货-账单
     */
    @Log(title = "易订货-账单", businessType = BusinessType.DELETE)
    @DeleteMapping
    @ApiOperation("删除易订货-账单")
    public AjaxResult remove(Long[] ids) {
        return toAjax(edhBillService.deleteEdhBillByIds(ids));
    }
}
